package ar.com.fiuba.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

/**
 * Class representing a n-gramm.
 * 
 */
@Entity
@Table (name = "NGRAMM")
public class Ngramm {

	private Long id;
	
	private Set<Word> words = new HashSet<Word>();
	
	private String value;
	
	public static Ngramm NullNgramm() {
		return new Ngramm();
	}

	public Ngramm(String value) {
		this.value = value;
	}

	public Ngramm() {
		super();
	}
	
	@Column(name = "value")
	public String getValue() {
		return value;
	}

	public boolean equals(Object obj) {
		return ((obj != null) && (this.value.equals(((Ngramm) obj).getValue())));
	}

	/**
	 * @return the id
	 */
	@Id
	@GeneratedValue
	@Column(name="id")	
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the words
	 */
	@ManyToMany(cascade = CascadeType.ALL, fetch = javax.persistence.FetchType.LAZY, targetEntity = Word.class)
	@JoinTable(name = "WORD_NGRAMM", joinColumns = { @JoinColumn(name = "NGRAMM_ID") }, inverseJoinColumns = { @JoinColumn(name = "WORD_ID") })
	public Set<Word> getWords() {
		return words;
	}

	/**
	 * @param words the words to set
	 */
	public void setWords(Set<Word> words) {
		this.words = words;
	}

	/**
	 * @param value the value to set
	 */
	public void setValue(String value) {
		this.value = value;
	}
	
	public String toString() {
		return this.value;
	}
	
	public int hashCode() {
		return this.value.hashCode();
	}

}
